package top.stacktrace.order.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;
import top.stacktrace.account.domain.User;
import top.stacktrace.order.domain.Order;

import java.util.List;

@Component
@Mapper
public interface OrderDao {
    @Insert("INSERT INTO `order` (`id`, `bookid`, `price`, `userid`, `status`, `createtime`, `updatetime`) " +
            "VALUES (#{id}, #{bookid}, #{price}, #{userid}, #{status}, now(), now())")
    int saveOrder(Order o);

    @Insert("INSERT INTO `order` (`id`, `bookid`, `price`, `userid`, `status`, `createtime`, `updatetime`) " +
            "VALUES ('1507237751461863424', #{bookid}, #{price}, #{userid}, #{status}, now(), now())")
    int saveOrderFailed(Order o);

    @Update("update `order` set `status`=#{status},`updatetime`=now() where `id`=#{id}")
    int updateOrderStatus(Order o);

    @Select("select * from `order` where `id`=#{id}")
    Order getOrderById(String id);

    @Select("select * from `order`")
    List<Order> getOrders();
}
